<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>积分商城管理 - 管理后台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            background: rgba(255, 255, 255, 0.95);
            padding: 20px;
            border-radius: 15px;
            margin-bottom: 30px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .header h1 {
            color: #667eea;
            font-size: 2.5rem;
            font-weight: 700;
            text-align: center;
            margin-bottom: 10px;
        }

        .nav-tabs {
            display: flex;
            gap: 10px;
            margin-top: 20px;
            flex-wrap: wrap;
        }

        .nav-tab {
            padding: 12px 20px;
            background: #f8f9fa;
            color: #666;
            text-decoration: none;
            border-radius: 8px;
            transition: all 0.3s ease;
            font-weight: 500;
            border: 2px solid transparent;
        }

        .nav-tab:hover {
            background: #e9ecef;
            transform: translateY(-2px);
        }

        .nav-tab.active {
            background: #667eea;
            color: white;
            border-color: #5a6fd8;
        }

        .content {
            background: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .page-title {
            color: #667eea;
            font-size: 2rem;
            font-weight: 600;
            margin-bottom: 30px;
            text-align: center;
        }

        .action-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            flex-wrap: wrap;
            gap: 15px;
        }

        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 25px;
            text-decoration: none;
            display: inline-block;
            margin-right: 12px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-weight: 600;
            font-size: 14px;
            position: relative;
            overflow: hidden;
        }

        .btn::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 0;
            height: 0;
            background: rgba(255,255,255,0.2);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            transition: width 0.3s ease, height 0.3s ease;
        }

        .btn:hover::before {
            width: 300px;
            height: 300px;
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #5a6fd8 100%);
            color: white;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #5a6fd8 0%, #4c63d2 100%);
            color: white;
            text-decoration: none;
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
        }

        .btn-sm {
            padding: 6px 12px;
            font-size: 0.8rem;
        }

        .btn-warning {
            background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
            color: #856404;
            box-shadow: 0 4px 15px rgba(255, 193, 7, 0.3);
        }

        .btn-warning:hover {
            background: linear-gradient(135deg, #e0a800 0%, #d39e00 100%);
            color: #856404;
            text-decoration: none;
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(255, 193, 7, 0.4);
        }

        .btn-danger {
            background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
            color: white;
            box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
        }

        .btn-danger:hover {
            background: linear-gradient(135deg, #c82333 0%, #bd2130 100%);
            color: white;
            text-decoration: none;
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(220, 53, 69, 0.4);
        }

        .btn-success {
            background: linear-gradient(135deg, #28a745 0%, #218838 100%);
            color: white;
            box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
        }

        .btn-success:hover {
            background: linear-gradient(135deg, #218838 0%, #1e7e34 100%);
            color: white;
            text-decoration: none;
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(40, 167, 69, 0.4);
        }

        .stats {
            display: flex;
            justify-content: space-between;
            gap: 20px;
            margin-bottom: 30px;
            flex-wrap: wrap;
        }

        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 25px;
            border-radius: 15px;
            text-align: center;
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            flex: 1;
            min-width: 200px;
        }

        .stat-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4);
        }

        .stat-card:hover::before {
            opacity: 1;
        }

        .stat-number {
            font-size: 2.5em;
            font-weight: 700;
            margin-bottom: 8px;
            position: relative;
            z-index: 1;
        }

        .stat-label {
            font-size: 1.1em;
            opacity: 0.9;
            position: relative;
            z-index: 1;
        }

        .items-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
        }

        .item-card {
            background: white;
            border: 1px solid #e9ecef;
            border-radius: 15px;
            padding: 25px;
            margin-bottom: 25px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.08);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .item-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%);
            transform: scaleY(0);
            transition: transform 0.3s ease;
        }

        .item-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(0,0,0,0.12);
            border-color: #FF6B6B;
        }

        .item-card:hover::before {
            transform: scaleY(1);
        }

        .item-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 15px;
        }

        .item-title {
            font-size: 1.2rem;
            font-weight: 600;
            color: #333;
            margin-bottom: 5px;
        }

        .item-status {
            display: inline-block;
            padding: 6px 16px;
            border-radius: 25px;
            font-size: 12px;
            font-weight: 700;
            margin-bottom: 15px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .status-available {
            background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .status-unavailable {
            background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .item-description {
            color: #555;
            margin-bottom: 20px;
            line-height: 1.6;
            font-size: 15px;
        }

        .item-details {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 15px;
            margin-bottom: 20px;
            padding: 20px;
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
            border-radius: 12px;
            border: 1px solid #dee2e6;
        }

        .detail-item {
            text-align: center;
        }

        .detail-label {
            font-size: 12px;
            color: #6c757d;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 5px;
        }

        .detail-value {
            font-weight: 700;
            font-size: 16px;
            color: #495057;
        }

        .item-actions {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #666;
        }

        .empty-state h3 {
            margin-bottom: 10px;
            color: #999;
        }

        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }

            .header h1 {
                font-size: 2rem;
            }

            .nav-tabs {
                justify-content: center;
            }

            .action-bar {
                flex-direction: column;
                align-items: stretch;
            }

            .items-grid {
                grid-template-columns: 1fr;
            }

            .item-details {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>🛠️ 管理后台</h1>
            <nav class="nav-tabs">
                <a href="/admin" class="nav-tab">📊 控制面板</a>
                <a href="/admin/users" class="nav-tab">👥 用户管理</a>
                <a href="/admin/knowledge" class="nav-tab">📚 科普管理</a>
                <a href="/admin/forum" class="nav-tab">💬 社区管理</a>
                <a href="/admin/points_shop" class="nav-tab active">🛒 积分商城</a>
                <a href="/admin/settings" class="nav-tab">⚙️ 系统设置</a>
            </nav>
        </header>

        <div class="content">
            <h1 class="page-title">🛒 积分商城管理</h1>

            <div class="action-bar">
                <div class="stats">
                    <div class="stat-card">
                        <div class="stat-number">{{ items|length }}</div>
                        <div class="stat-label">总商品数</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-number">{{ items|selectattr('is_available')|list|length }}</div>
                        <div class="stat-label">可用商品</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-number">{{ items|selectattr('stock', 'gt', 0)|list|length }}</div>
                        <div class="stat-label">有库存</div>
                    </div>
                </div>
                <a href="/admin/points_shop/add" class="btn btn-primary">
                    ➕ 添加商品
                </a>
            </div>

            {% if items %}
            <div class="items-grid">
                {% for item in items %}
                <div class="item-card">
                    <div class="item-header">
                        <div>
                            <div class="item-title">{{ item.name }}</div>
                        </div>
                        <div class="item-status {{ 'status-available' if item.is_available else 'status-unavailable' }}">
                            {{ '可用' if item.is_available else '不可用' }}
                        </div>
                    </div>
                    
                    <div class="item-description">
                        {{ item.description or '暂无描述' }}
                    </div>
                    
                    <div class="item-details">
                        <div class="detail-item">
                            <div class="detail-value">{{ item.points_cost }}</div>
                            <div class="detail-label">所需积分</div>
                        </div>
                        <div class="detail-item">
                            <div class="detail-value">
                                {% if item.stock == -1 %}
                                ∞
                                {% else %}
                                {{ item.stock }}
                                {% endif %}
                            </div>
                            <div class="detail-label">库存</div>
                        </div>
                        <div class="detail-item">
                            <div class="detail-value">{{ item.category }}</div>
                            <div class="detail-label">类型</div>
                        </div>
                    </div>
                    
                    <div class="item-actions">
                        <a href="/admin/points_shop/edit/{{ item.id }}" class="btn btn-warning btn-sm">
                            ✏️ 编辑
                        </a>
                        <a href="/admin/points_shop/delete/{{ item.id }}" class="btn btn-danger btn-sm"
                           onclick="return confirm('确定要删除此商品吗？此操作不可撤销！')">
                            🗑️ 删除
                        </a>
                    </div>
                </div>
                {% endfor %}
            </div>
            {% else %}
            <div class="empty-state">
                <h3>🛒 暂无商品</h3>
                <p>积分商城中还没有任何商品，<a href="/admin/points_shop/add" style="color: #667eea;">点击添加</a>第一个商品</p>
            </div>
            {% endif %}
        </div>
    </div>

    <script>
        // 自动刷新页面数据
        setInterval(function() {
            // 可以添加AJAX刷新逻辑
        }, 30000);
    </script>
</body>
</html>